/********************************************************/
/*	Logger class by George Chew						*/
/*	For use in GeorgeLib								*/
/*	Created Mar 2013									*/
/*														*/
/*	Version 0001										*/
/********************************************************/

#ifndef __LOGGER_H__
#define __LOGGER_H__

#include "stdafx.h"
#include <fstream>	// fstream for file output
#include <cstdarg>	// stdarg.h for argument list

#define Logger GeorgeLib::_Logger::getInstance()

namespace GeorgeLib
{

	class DLLEXPORT _Logger
	{

		/*		How to use this class 		*/
		// Logger->AddLog("Hello World, Logger Message");
		// Logger->LoadFile("CLASS_ERRORS.txt");
		// Logger->AddLog("CLASS\t\t: Function - Error Message");
		// *Logger << 5.0 << '\n' << vec3(1,2,3) << '\n';

	private:
		static	_Logger*	Logger_Instance;// Singleton Instance
		static	char*		Destination;	// File output destination
		static	ofstream	FileStream;		// STD output stream to file

	public:
		_Logger(void);			// Constructor
		~_Logger(void);			// Destructor	: Close the output file stream

		// Get the singleton instance of this class 
		static	_Logger*	getInstance(void);

		// Write a message to the file
		// Example output : Mar  1 2013 15:38:00 message
		// There will always be line break, unless specified
		void	AddLog(string message, bool endline = true, bool timestamp = false);
		void	AddLog(char * message, bool endline = true, bool timestamp = false);

		// Redefine a new output file destination
		void	LoadFile(char * filename);

		// Closes the current file
		void	CloseFile(void);

		// Output variables to the file
		friend	_Logger&	operator<<	(_Logger & logger, string var);
		friend	_Logger&	operator<<	(_Logger & logger, __int8 var);
		friend	_Logger&	operator<<	(_Logger & logger, unsigned __int8 var);
		friend	_Logger&	operator<<	(_Logger & logger, __int16 var);
		friend	_Logger&	operator<<	(_Logger & logger, unsigned __int16 var);
		friend	_Logger&	operator<<	(_Logger & logger, __int32 var);
		friend	_Logger&	operator<<	(_Logger & logger, unsigned __int32 var);
		friend	_Logger&	operator<<	(_Logger & logger, __int64 var);
		friend	_Logger&	operator<<	(_Logger & logger, unsigned __int64 var);
		friend	_Logger&	operator<<	(_Logger & logger, float var);
		friend	_Logger&	operator<<	(_Logger & logger, double var);
	};

} // namespace GeorgeLib

#endif // __LOGGER_H__ //